const SetStorage = (key, value, expiryInMilliseconds = 1000 * 60 * 60 * 24) => {
    const item = { value, expiry: new Date().getTime() + expiryInMilliseconds };
    localStorage.setItem(key, JSON.stringify(item));
};

const GetStorage = (key) => {
    try {
        const item = JSON.parse(localStorage.getItem(key));
        if (item) {
            if (item.expiry > new Date().getTime()) {
                return item.value;
            }
            localStorage.removeItem(key);
            return {};
        }
        return {};
    } catch (error) {
        return {};
    }
};

const ClearStorage = (key) => {
    localStorage.setItem(key, JSON.stringify({}));
};

const Sleep = (times = 800) =>
    new Promise((resolve) => setTimeout(resolve, times));

export { SetStorage, GetStorage, ClearStorage, Sleep };
